import java.util.*;

public class Vertex {
	private int index;
	public boolean visited;
	
	public Vector<Edge> vecEdges = new Vector<Edge>();
	public Edge edges[];
			
	public Vertex(){
	}
	
	public Vertex (int i) {
		index = i;
	}
	
	public void print() {
		System.out.println(edges.length);
	}
	
	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public void printIndex() {
		System.out.println(index);
	}
	
	public int connectedTo(Vertex vert) {
		for (int i = 0; i < edges.length; i++) {
			if (edges[i].hasVertex(vert))
				return i;
		}
		
		return -1;
	}
	//Use with Vector implementation
	private Edge[] vecToArray() {
		Edge temp[] = new Edge[vecEdges.size()];
		
		for (int i = 0; i < vecEdges.size(); i++) {
			temp[i] = vecEdges.get(i);
		}
		
		return temp;
	}
	
	public void sort() {
		edges = vecToArray();
		
		Arrays.sort(edges, new Comparator<Edge>(){	
									public int compare(Edge e1, Edge e2) {
									return Double.compare(e1.getWeight(), e2.getWeight());
								}});
	}
	
	public Edge greedyNext() {
		for (int i = 0; i < edges.length; i++) {
			if (!edges[i].getV2().visited) {
				return edges[i];
			}
		}
		
		return null;
	}
	
}
